﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Wusong.Gold.DataService
{
    /// <summary>
    /// http://quote.zhijinwang.cn/xml/gold.txt?随机数
    /// time=15:29:49&gold=|298.44|298.04|298.84|299.04|293.42|1394.10|76.58|87.40
    /// </summary>
    public class ZJWResource : IResourceBase
    {
        Random rdm = new Random();
        public string DataUri
        {
            get
            {
                return string.Format("http://quote.zhijinwang.cn/xml/gold.txt?{0}", rdm.Next());
            }

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="textValue"></param>
        /// <returns> MsgTime ,MidPrice, SalePrice ,BuyPrice ,DollarPrice, DollarIndex ,OilIndex
        ///  </returns>
        public GoldMsg Formart(string textValue)
        {
            string[] timeAndValue = textValue.Split('&');
            string time = timeAndValue[0];
            string[] timeArr = time.Split(':');
            string[] valueArr = timeAndValue[1].Split('|');
            GoldMsg msg = new GoldMsg();
            msg.MsgTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, int.Parse(timeArr[0].Split('=')[1]), int.Parse(timeArr[1]), int.Parse(timeArr[2]));
            msg.MidPrice = double.Parse(valueArr[1]);
            msg.SalePrice = double.Parse(valueArr[2]);
            msg.BuyPrice = double.Parse(valueArr[3]);
            msg.DollarPrice = double.Parse(valueArr[6]);
            msg.DollarIndex = double.Parse(valueArr[7]);
            msg.OilIndex = double.Parse(valueArr[8]);
            return msg;
        }

    }
}
